package com.ontology.util.model.impl;
import java.text.SimpleDateFormat;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.ontology.util.ODataType;
import com.ontology.util.model.OColumn;
public class OntologyColumn implements OColumn {
	private ODataType			type;
	private String				name;
	private Boolean				mandatory	= Boolean.FALSE;
	private SimpleDateFormat	dateFormat;
	private ODataType			upgradeAbleType;
	public ODataType getType() {
		return type;
	}
	public String getName() {
		return name;
	}
	public Boolean isMandatory() {
		return mandatory;
	}
	public SimpleDateFormat getDateFormat() {
		return dateFormat;
	}
	public void setType(ODataType type) {
		this.type = type;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setMandatory(Boolean mandatory) {
		this.mandatory = mandatory;
	}
	public void setDateFormat(SimpleDateFormat dateFormat) {
		this.dateFormat = dateFormat;
	}
	public ODataType getUpgradeAbleType() {
		return upgradeAbleType;
	}
	public void setUpgradeAbleType(ODataType upgradeAbleType) {
		this.upgradeAbleType = upgradeAbleType;
	}
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer("{name=").append(name);
		sb.append(",type=").append(type);
		sb.append(",mandatory=").append(mandatory);
		sb.append(",dateFormat=").append(dateFormat == null
		? null
		: dateFormat.toPattern());
		sb.append("}");
		return sb.toString();
	}
	public String getDatePattern() {
		return dateFormat == null ? null : dateFormat.toPattern();
	}
	@Override
	public boolean equals(Object obj) {
		OntologyColumn other = (OntologyColumn) obj;
		if (other == null) {
			return false;
		}
		EqualsBuilder equalsBuilder = new EqualsBuilder();
		equalsBuilder.append(name, other.getName());
		equalsBuilder.append(type, other.getType());
		equalsBuilder.append(getDatePattern(), other.getDatePattern());
		return equalsBuilder.isEquals();
	}
	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(name).append(type).append(getDatePattern()).toHashCode();
	}
}
